package edu.ustb.services.weatherforecast.contract;

import edu.ustb.sc.definitions.*;
/*
* term no3_1: Customer can request(WeatherForecast)
*   when exist WeatherForecast.UseRight.Customer
*   while deposit price
*   where this.balance >= price.
*
*
* */
public class ServiceTerm3_1 extends SpescContractTerm <ServiceContract>{

    public ServiceContractParty partyInfo = new ServiceContractParty("Customer");

    public static SpescTermActionQualifierEnum qualifier = SpescTermActionQualifierEnum.Can;

    public static String actionName = "request";

    public ServiceTerm3_1() {
        try {
            actionInfo = new ContractActionInfo();
            actionInfo.setAction(ServiceContract.class.getMethod("request", String.class,String.class));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    @Override
    public TermLogicEnum getLogic() {
        return null;
    }

    @Override
    public String getTermName() {
        return "ServiceTerm3_1";
    }

    @Override
    public SpescTermActionQualifierEnum getQualifier() {
        return qualifier;
    }

    @Override
    public ContractPartyInfo getPartyInfo() {
        return partyInfo;
    }

    @Override
    public SpescConditionCheckStatus whenPreCondition(ServiceContract contract, Object... param) {
        String partyName = (String) param[0];
        if(contract.data.userRight.getOrDefault(partyName,false)==true)
           return SpescConditionCheckStatus.Yes;
        return SpescConditionCheckStatus.No;
    }

    @Override
    public SpescConditionCheckStatus wherePostCondition(ServiceContract contract, Object... param) {
        return SpescConditionCheckStatus.Yes;
    }
}
